#include <stdio.h>
int DayofYear(int year,int month,int day)
{
    int allday=0,i;
    int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    if((0==year%4&&0!=year%100)||0==year%400)
    {
        for(i=0;i<month-1;i++)
        {
            allday+=a[i];
        }
        allday+=day;
    }
    else
    {
        for(i=0;i<month-1;i++)
        {
            allday+=b[i];
        }
        allday+=day;
    }
    return allday;
}
void MonthDay(int year,int yearDay,int *pMonth,int *pDay)
{
    int i;
    int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    if((0==year%4&&0!=year%100)||0==year%400)
    {
        for(i=0;i<12;i++)
        {
            yearDay-=a[i];
            if(yearDay<=0)
            {
                yearDay+=a[i];
                break;
            }
        }
        *pMonth=i+1;
        *pDay=yearDay;
    }
    else
    {
        for(i=0;i<12;i++)
        {
            yearDay-=b[i];
            if(yearDay<=0)
            {
                yearDay+=b[i];
                break;
            }
        }
        *pMonth=i+1;
        *pDay=yearDay;
    }
}
void main()
{
    int year,month,yearDay,day,option;
    printf("1.year/month/day -> yearDay\n");
    printf("2.yearDay -> year/month/day\n");
    printf("3.Exit\n");
    printf("please enter your choice:");
    scanf("%d",&option);
    switch(option)
    {
    case 1:
        printf("please input the year:");
        scanf("%d",&year);
        printf("And please input the month:");
        scanf("%d",&month);
        printf("And again the date:");
        scanf("%d",&day);
        printf("the day is No.%d day in this year.",DayofYear(year,month,day));
        break;
    case 2:
        printf("please input the year:");
        scanf("%d",&year);
        printf("please input how many days have passed since the year:");
        scanf("%d",&yearDay);
        MonthDay(year,yearDay,&month,&day);
        printf("this is the %d months and the %d days of this year.",month,day);
        break;
    case 3:
        exit(0);
        break;
    default:
        printf("please choose the legal option!");
    }
}
